// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

const int N = 5e3+50;

int tt, n, m;
char s[N];
char ans[N], t[N];
int main(int argc, char const *argv[]) {
    // code
    scanf("%d", &tt);
    for (int kk=0; kk<tt; ++kk) {
        scanf("%d", &n); 
        memset(s, 0, n+1);
        memset(t, 0, n+1);
        memset(ans, 0, n+1);
        scanf("%s", s);
        strcpy(ans, s);

        int ansk = 1;
        for (int i=2; i<=n; ++i) {
            memcpy(t, s+i-1, n-i+1);
            memcpy(t+n-i+1, s, i-1);
            int times = n-i+1;
            if (times & 1)
                reverse(t+n-i+1, t+n);
            if (strcmp(t, ans) < 0)
            {
                ansk = i;
                strcpy(ans, t);
            }
        }


        printf("%s\n", ans);
        printf("%d\n", ansk);
    }
    return 0;
}
